package com.yjd.comm.system.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yjd.comm.base.enums.DbWREnums;
import com.yjd.comm.baseInfo.model.BannerModel;
import com.yjd.comm.baseInfo.service.IBannerService;
import com.yjd.comm.cache.CachedUtil;
import com.yjd.comm.util.ServiceHolder;

public class BannerUtil {

	@SuppressWarnings("unchecked")
	public static List<BannerModel> getBanners() throws Exception {
		List<BannerModel> list = (List<BannerModel>) CachedUtil.defaultCached()
				.get("banner");
		if (list == null) {
			return freshCache();
		}
		return list;
	}

	@SuppressWarnings("unchecked")
	public static List<BannerModel> freshCache() throws Exception {
		IBannerService service = ServiceHolder.getService(IBannerService.class,
				"bannerService");
		Map<String, String> parm = new HashMap<String, String>();
		parm.put("sort", "sort asc");
		List<BannerModel> banners = service.getModelList(parm,DbWREnums.READ);
		if (banners == null) {
			CachedUtil.defaultCached().set("banner", 60 * 60 * 24, banners);
		}
		return banners;
	}
}
